package com.hudongwx.yuan_sdjj.fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hudongwx.yuan_sdjj.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * A simple {@link Fragment} subclass.
 */
@ContentView(R.layout.fragment_good)
public class GoodFragment extends Fragment {
    @ViewInject(R.id.good_tab_layout)
    private TabLayout tabLayout;
    @ViewInject(R.id.good_view_pager)
    private ViewPager viewPAger;
    private Fragment [] pages= new Fragment[2];
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = x.view().inject(this, inflater, container);
        viewPAger.setAdapter(new MyFragmentAdapter(getFragmentManager()));
        tabLayout.setupWithViewPager(viewPAger);
        return view;
    }
    //分开两个fragment
    class MyFragmentAdapter extends FragmentPagerAdapter{
        public MyFragmentAdapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public Fragment getItem(int position) {
            switch (position){
                case 0:
                    if(null==pages[position])
                        pages[position]= new GatherPraiseerFragment();
                    break;
                case 1:
                    if(null==pages[position])
                        pages[position]= new MyPraiseFragment();
                    break;
            }
            return pages[position];
        }

        @Override
        public int getCount() {
            return 2;
        }
        //设置标题
        @Override
        public CharSequence getPageTitle(int position) {
            if(0==position){
                return "聚赞";
            }else {
                return "我的聚赞";
            }
        }
    }
}
